package gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

public class TelaNovoTipo extends JDialog implements KeyListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JPanel contentPane;
	
	private JPanel panelPrincipal;
	private JPanel panelNovoTipo;
	
	private JScrollPane scrollPaneDescricao;
	private JTextArea textAreaDescricaoTipoAto;
	private JTextField textPrazo;

	private JButton botaoCancelar;
	private JButton botaoCadastrar;

	/**
	 * Create the frame.
	 */
	public TelaNovoTipo(JFrame pai) {
		super(pai, "Cadastrar Novo Tipo de Ato Processual");
		this.addKeyListener(this);
		initialize();
	}
	
	@Override
	public void keyPressed(KeyEvent e) {
		if(e.getKeyCode()==KeyEvent.VK_ESCAPE)
			TelaNovoTipo.this.dispose();
	}

	@Override
	public void keyReleased(KeyEvent e) {
	}

	@Override
	public void keyTyped(KeyEvent e) {
	}

	private void initialize(){
		setResizable(false);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 187);
		setLocationRelativeTo(null);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		panelPrincipal = new JPanel();
		contentPane.add(panelPrincipal, BorderLayout.CENTER);
		
		panelNovoTipo = new JPanel();
		panelNovoTipo.setBorder(new TitledBorder(null, "", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		
		JLabel labeDescricao = new JLabel("Descri\u00E7\u00E3o");
		
		scrollPaneDescricao = new JScrollPane();
		
		JLabel labelPrazo = new JLabel("Prazo (n\u00B0 de dias)");
		
		textPrazo = new JTextField();
		textPrazo.setHorizontalAlignment(SwingConstants.CENTER);
		textPrazo.setColumns(10);
		GroupLayout gl_panelNovoTipo = new GroupLayout(panelNovoTipo);
		gl_panelNovoTipo.setHorizontalGroup(
			gl_panelNovoTipo.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_panelNovoTipo.createSequentialGroup()
					.addGroup(gl_panelNovoTipo.createParallelGroup(Alignment.LEADING)
						.addComponent(labeDescricao)
						.addComponent(scrollPaneDescricao, GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_panelNovoTipo.createParallelGroup(Alignment.LEADING)
						.addComponent(labelPrazo)
						.addComponent(textPrazo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
		);
		gl_panelNovoTipo.setVerticalGroup(
			gl_panelNovoTipo.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelNovoTipo.createSequentialGroup()
					.addGroup(gl_panelNovoTipo.createParallelGroup(Alignment.BASELINE)
						.addComponent(labeDescricao)
						.addComponent(labelPrazo))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panelNovoTipo.createParallelGroup(Alignment.LEADING)
						.addComponent(textPrazo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(scrollPaneDescricao, GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE))
					.addContainerGap())
		);
		
		textAreaDescricaoTipoAto = new JTextArea();
		scrollPaneDescricao.setViewportView(textAreaDescricaoTipoAto);
		panelNovoTipo.setLayout(gl_panelNovoTipo);
		
		botaoCancelar = new JButton("Cancelar");
		botaoCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TelaNovoTipo.this.dispose();
			}
		});
		
		botaoCadastrar = new JButton("Cadastrar");
		GroupLayout gl_panelPrincipal = new GroupLayout(panelPrincipal);
		gl_panelPrincipal.setHorizontalGroup(
			gl_panelPrincipal.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelPrincipal.createSequentialGroup()
					.addGroup(gl_panelPrincipal.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panelPrincipal.createSequentialGroup()
							.addGap(5)
							.addComponent(panelNovoTipo, GroupLayout.PREFERRED_SIZE, 422, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panelPrincipal.createSequentialGroup()
							.addContainerGap()
							.addComponent(botaoCancelar, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
							.addGap(256)
							.addComponent(botaoCadastrar, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		gl_panelPrincipal.setVerticalGroup(
			gl_panelPrincipal.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panelPrincipal.createSequentialGroup()
					.addContainerGap()
					.addComponent(panelNovoTipo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panelPrincipal.createParallelGroup(Alignment.LEADING)
						.addComponent(botaoCancelar, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(botaoCadastrar, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(92, Short.MAX_VALUE))
		);
		panelPrincipal.setLayout(gl_panelPrincipal);
	}
}
